<template>
  <div>
    <el-table :data="userMessage" style="width: 100%">
      <el-table-column prop="username" label="姓名" width="140">
      </el-table-column>
      <el-table-column prop="nickname" label="昵称" width="140">
      </el-table-column>
      <el-table-column prop="sex" label="性别"> </el-table-column>
      <el-table-column prop="age" label="年龄"> </el-table-column>
      <el-table-column prop="city" label="城市"> </el-table-column>
      <el-table-column prop="tle" label="电话"> </el-table-column>
      <el-table-column prop="plike" label="喜好"> </el-table-column>
      <el-table-column prop="email" label="邮箱"> </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            type="danger"
            icon="el-icon-delete"
            circle
            @click="deleteUser(scope.row.tle, scope.row.username)"
          ></el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
export default {
  name: "usermanage",
  data() {
    return {
      userMessage: [],
    };
  },
  mounted() {
    this.selctAll();
  },
  methods: {
    //查询所有用户的信息
    selctAll() {
      let url = "/user/selectById";
      let param = "";
      this.$axios
        .get(url, param)
        .then((resp) => {
          this.userMessage = resp.data;
        })
        .catch((err) => {
          console.log("error=", err);
        });
    },
    //删除用户
    deleteUser(tle, username) {
      let url = "/user/delete";
      let user = {
        tle: tle,
      };
      let param = this.$qs.stringify(user);
      this.$confirm("此操作将永久删除" + username + "用户, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$axios
            .post(url, param)
            .then((resp) => {
              if (resp.data) {
                this.$message({
                  type: "success",
                  message: "删除成功!",
                });
                this.selctAll();
              } else {
                this.$message({
                  type: "error",
                  message: "删除失败!",
                });
              }
            })
            .catch((err) => {
              console.log("error=", err);
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
  },
};
</script>
<style scoped>
.el-table .cell {
  text-align: center;
}
</style>